<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
	
	<xsl:key name="nodes" match="node" use="@id"/>
	
	<xsl:template match="/">
		<h1>Significant properties </h1>
		<table width="100%">
			<tbody>
				<tr>
					<td valign="top" width="30%">
						<a name="toc"/>
						<xsl:apply-templates mode="toc"/>
					</td>
					<td>
						<xsl:apply-templates/>
					</td>
				</tr>
			</tbody>
		</table>
	</xsl:template>
	
	<xsl:template match="node" mode="toc">
		<a href="#{generate-id()}">
			<xsl:value-of select="@id"/>
			<xsl:text>: </xsl:text>
			<xsl:value-of select="@label"/>
		</a>
		<br/>
		<xsl:apply-templates mode="toc" select="isComposedBy"/>
	</xsl:template>
	
	<xsl:template match="text()" mode="toc" priority="-1"/>
	
	<xsl:template match="node">
		<hr/>
		<h4>
			<xsl:if test="@id">
				<a name="{@id}"/>
			</xsl:if>
			<a name="{generate-id()}"/>
			<xsl:value-of select="@label"/>
		</h4>
		<h5>
			Path: 
			<xsl:for-each select="ancestor-or-self::node">
				<xsl:value-of select="@label"/>
				<xsl:text>/</xsl:text>
			</xsl:for-each>
		</h5>
		<xsl:if test="ancestor::node">
			<h5>
				[<a href="#{ancestor::node[1]/@id}">Back to parent</a>]
				[<a href="#toc">TOC</a> ] 
			</h5>
		</xsl:if>
		<xsl:if test="isComposedBy">
			Is composed by:
			<ul>
				<xsl:for-each select="isComposedBy/node">
					<xsl:choose>
						<xsl:when test="@id">
							<li><a href="#{@id}"> <xsl:value-of select="@label"/> </a></li>
						</xsl:when>
						<xsl:otherwise>
							<li><xsl:value-of select="@label"/></li>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</ul>
		</xsl:if>
		<xsl:if test="isRelatedTo">
			Is related to:
			<ul>
				<xsl:for-each select="isRelatedTo/node">
					<li><a href="#{@id}"> <xsl:value-of select="key('nodes',@id)/@label"/></a></li>
				</xsl:for-each>
			</ul>
		</xsl:if>
		
		<xsl:apply-templates select="isComposedBy"/>
	</xsl:template>
</xsl:stylesheet>
